package ship;

import java.util.ArrayList;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;

import ship.weapon.IWeapon;
import ship.weapon.Laser;

import cells.ICell;


public class Ship {
	private ArrayList<IWeapon> weapons;
	private IWeapon currentWeapon;
	private Body m_body;
	
	public Ship(Body body) {
		m_body = body;
		m_body.setUserData(this);
		weapons = new ArrayList<>();
		weapons.add(new Laser(this));
		chooseWeapon(1);
	}
	
	public Body getBody() {
		return m_body;
	}
	
	public void move(Vector2 vec) {
		m_body.setLinearVelocity(vec);
	}
	
	public void chooseWeapon(int number) {
		if (number <= weapons.size()) {
			IWeapon newWeapon = weapons.get(number - 1);
			if (currentWeapon == null) {
				currentWeapon = newWeapon;
				currentWeapon.choose();
			} else {
				if (currentWeapon != newWeapon) {
					currentWeapon.unchoose();
					currentWeapon = weapons.get(number);
					currentWeapon.choose();
				}
			}
		}	
	}
	
	public void mouseDown(Vector2 point) {
		currentWeapon.mouseDown(point);
	}
	
	public void mouseMoving(Vector2 point) {
		currentWeapon.mouseMoving(point.add(this.getBody().getWorldCenter().rotate(180)));
	}
	
	public void mouseUp(Vector2 point) {
		currentWeapon.mouseUp(point);
	}


}
